package com.yc.jpyy.terminator.controller;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.TeacherDao;
import com.yc.jpyy.mobile.service.TeacherService;

@Controller
@RequestMapping(value = "/terminator")
public class CourseController extends BaseController{
	
	//private static Logger logger = LoggerFactory.getLogger(CourseController.class);	
	@Autowired
	private TeacherService teacherService;
	@Autowired
	private TeacherDao teacherDao;
	
	/**
	 *2.6	预约教程信息获取
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getAppointMentTeachCourses", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody String getAppointMentTeachCourses(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {

			//教练id
			String coachNum = request.getParameter("coachNum");
			if(coachNum!=null&&!coachNum.isEmpty())
			{
				
				List<Map<String, Object>> appointCourseList=teacherDao.getAppointMentTeachCourses(coachNum);
				if (appointCourseList != null && appointCourseList.size() > 0) {
					response.setData(appointCourseList);
				}else {
					response.setErrorcode(1);
					response.setMessage("该教练无预约教程信息...");
				}
			}else
			{
				response.setErrorcode(1);
				response.setMessage("教练全国编号不能为空...");
			}
				
		} catch (Exception e) {
			System.out.println("getAppointMentTeachCourses:"+ e.toString());
			response.setReturnMsg(1,"预约教程信息获取失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	
	/**
	 * 2.4	培训记录信息获取
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getTrainingRecords", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody String getTrainingRecords(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {

			//教练编号
			String coachNum = request.getParameter("coachNum");
			//日期
			String date = request.getParameter("date");
			if(coachNum!=null&&!coachNum.isEmpty() && date!=null&&!date.isEmpty())
			{
				Map<String, Object> paramsMap = new HashMap<String, Object>();
				paramsMap.put("coachNum", coachNum);
				paramsMap.put("date", date);
				List<Map<String, Object>> stumap=teacherDao.getTrainingRecords(paramsMap);
				if (stumap != null && stumap.size() > 0) {
					 
					// 设置Json集合
					response.setData(stumap);
				} else {
					response.setErrorcode(1);
					response.setMessage("该教练无培训记录信...");
				}
			}
			else
			{
				response.setErrorcode(1);
				response.setMessage("教练全国编号、日期不能为空...");
			}

		} catch (Exception e) {
			System.out.println("getTrainingRecords:"+ e.toString());
			response.setReturnMsg(1,"获取教练培训记录信失败！");
		} finally {
			return response.toJSON();
		}
	}
}
